﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.Data;
using System.Data;

namespace blackhouse.BlackApart.Data.Sql {
    public class PricesDataAccess : AdoPricesDataAccess {

        #region Fields

        private string connectionString;
        private MsSqlAdoDataHelper dataHelper;

        #endregion

        #region Constructors

        public PricesDataAccess(string sqlConnectionString) {
            this.connectionString = sqlConnectionString;
            this.dataHelper = new MsSqlAdoDataHelper(this.connectionString);
            SqlVersioning versioning = new SqlVersioning(this.connectionString, this.GetType().Assembly);
        }

        #endregion

        #region AdoPricesDataAccess Members

        protected override IDataReader GetReaderForPriceRabats(string language, int apartmentTypeId) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_PriceRabats";
            this.dataHelper.AddParameter("Language", language, DbType.StringFixedLength);
            this.dataHelper.AddParameter("ApartmentTypeId", apartmentTypeId, DbType.Int32);
            return this.dataHelper.Execute();
        }

        protected override IDataReader GetReaderForPrices(int apartmentId) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_ApartmentPriceModificationsGet";
            this.dataHelper.AddParameter("ApartmentId", apartmentId, System.Data.DbType.Int32);
            return this.dataHelper.Execute();
        }

        public override double GetApartmentPrice(int apartmentId) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_ApartmentPriceGet";
            this.dataHelper.AddParameter("ApartmentId", apartmentId, System.Data.DbType.Int32);
            return Convert.ToDouble(this.dataHelper.ExecuteScalar());
        }

        protected override IDataReader GetReaderForPriceProfileVariants(int apartmentId) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_PriceProfileVariantsGet";
            this.dataHelper.AddParameter("ApartmentId", apartmentId, System.Data.DbType.Int32);
            return this.dataHelper.Execute();
        }

        protected override IDataReader GetReaderForPriceProfileDateModification(int apartmentId) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_PriceProfileDateModificationGet";
            this.dataHelper.AddParameter("ApartmentId", apartmentId, System.Data.DbType.Int32);
            return this.dataHelper.Execute();
        }

        protected override IDataReader GetReaderForPriceProfileLengthOfStayModification(int apartmentId) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_PriceProfileLengthOfStayModificationGet";
            this.dataHelper.AddParameter("ApartmentId", apartmentId, System.Data.DbType.Int32);
            return this.dataHelper.Execute();
        }

        protected override IDataReader GetReaderForApartmentDbPrice(DateTime startDate, DateTime endDate, int apartmentId, int peopleCount) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_ApartmentPriceProfileGet";
            this.dataHelper.AddParameter("ArrivalDate", startDate, DbType.DateTime);
            this.dataHelper.AddParameter("DepartureDate", endDate, DbType.DateTime);
            this.dataHelper.AddParameter("ApartmentId", apartmentId, DbType.Int32);
            this.dataHelper.AddParameter("PeopleCount", peopleCount, DbType.Int32);
            return this.dataHelper.Execute();
        }

        #endregion

    }
}
